<template>
  <div class="relative w-full h-full">
    <PageHeader title="文章管理" />
    <SearchCom :searchList="searchConfig" @search="handleSearch" />
    <div class="mt12 toolbar flex_aic_jcsb">
      <div class="addBtn flex_aic_jcc" @click="handleAdd">
        <SvgIcon name="iconxinzeng" class="mr8" />
        <span>新增文章</span>
      </div>
    </div>
    <el-table
      :data="tableData"
      style="width: 100%"
      class="cover-table mt12"
      border
    >
      <el-table-column prop="name" label="文章标题" />
      <el-table-column prop="create_time" label="创建时间" />
      <el-table-column label="操作">
        <template #default="scope">
          <div class="flex_aic_jcc">
            <div class="operationBtn">
              <el-button type="text" size="small" @click="handleEdit(scope.row)"
                >编辑</el-button
              >
            </div>
            <el-popconfirm
              title="确定删除吗？"
              @confirm="handleDelete(scope.row)"
              confirm-button-text="确定"
              cancel-button-text="取消"
            >
              <template #reference>
                <el-button class="ml0" type="text" size="small">删除</el-button>
              </template>
            </el-popconfirm>
          </div>
        </template>
      </el-table-column>
    </el-table>

    <div class="flex justify-end mt24 absolute bottom-0 right-0">
      <el-pagination
        v-model:current-page="currentPage"
        v-model:page-size="pageSize"
        :page-sizes="[10, 20, 30, 40]"
        layout="total, sizes, prev, pager, next, jumper"
        :total="400"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
  </div>
</template>

<script setup>
import { ref } from "vue";
import { useRouter } from "vue-router";
import SearchCom from "@/components/SearchCom.vue";
const router = useRouter();
const searchConfig = ref([
  {
    label: "文章标题",
    prop: "name",
    type: "input",
  },
]);
const currentPage = ref(1);
const pageSize = ref(10);
const tableData = ref([
  {
    id: 1,
    name: "服务保障",
    create_time: "2024-01-01 12:00:00",
  },
  {
    id: 2,
    name: "优惠券规则",
    create_time: "2024-01-01 12:00:00",
  },
  {
    id: 3,
    name: "使用帮助",
    create_time: "2024-01-01 12:00:00",
  },
  {
    id: 4,
    name: "平台介绍",
    create_time: "2024-01-01 12:00:00",
  },
]);
const handleDelete = (row) => {
  console.log(row);
};
const handleEdit = (row) => {
  router.push({
    path: "/articleManage/edit",
    query: {
      id: row.id,
    },
  });
};
const handleSizeChange = (size) => {
  pageSize.value = size;
};
const handleCurrentChange = (page) => {
  currentPage.value = page;
};
const handleAdd = () => {
  router.push("/articleManage/edit");
};
</script>

<style lang="scss" scoped>
.addBtn {
  height: 28px;
  margin-left: 10px;
  padding: 0 7px;
  border-radius: 3px;
  background: #fff;
  cursor: pointer;
}
.split {
  width: 1px;
  height: 12px;
  background: #ddd;
  margin: 0 5px;
}
</style>
